package cn.yusei.teamTribe.dao.team;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import cn.yusei.teamTribe.dao.team.po.TeamPO;

@Mapper
public interface TeamDAO {

	final String TEAM_TABLE = " e_team ";
	final String TEAM_TAG_TABLE = " r_team_tag";
	final String INSERT_FIELDS = "(school_id, name, comment)";
	
	@Select({"select id from", TEAM_TABLE, "where school_id = #{schoolId}"})
	int[] selectBySchool(@Param("schoolId") int schoolId);
	
	@Select({"select team_id from", TEAM_TAG_TABLE, "where tag_id = #{tagId}"})
	int[] selectByTag(@Param("tagId") int tagId);
	
	@Insert({"insert into ",TEAM_TABLE,INSERT_FIELDS," values(#{schoolId},#{name},#{comment})"})
	void insert(TeamPO teamPO);
	
	@Select({"select last_insert_id()"})
	int selectLastInsertId();
	
	@Select({"select exists (select * from ",TEAM_TABLE,"where school_id = #{schoolId} and name = #{name} limit 1)"})
	boolean exists(TeamPO teamPO);

	
}
